package com.ericsson.enap.modules.monitor.task;

import com.ericsson.enap.modules.topology.entity.CabSwitch;
import com.ericsson.enap.modules.monitor.entity.SwitchInterfaceStatus;
import com.ericsson.enap.modules.monitor.entity.SwitchPortData;
import com.ericsson.enap.modules.monitor.entity.SwitchTotalData;
import com.ericsson.common.quartz.task.ManualTask;
import com.ericsson.enap.modules.monitor.service.SwitchDBDataService;
import com.ericsson.enap.modules.monitor.service.SwitchEquipDataService;
import com.ericsson.common.util.*;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 设备状态获取任务
 */
@Component
public class CabSwitchDataTask implements ManualTask {

    private int port=23;
    @Autowired
    @Qualifier("h3c")
    public SwitchEquipDataService switchDataService_H3C;
    @Autowired
    @Qualifier("rj")
    public SwitchEquipDataService switchDataService_rj;
    @Autowired
    @Qualifier("zte")
    public SwitchEquipDataService switchDataService_zte;
    @Autowired
    @Qualifier("dell")
    public SwitchEquipDataService switchDataService_dell;
    @Autowired
    @Qualifier("hw")
    public SwitchEquipDataService switchDataService_hw;
    @Autowired
    @Qualifier("extreme")
    public SwitchEquipDataService switchDataService_extreme;

    @Autowired
    public SwitchDBDataService switchDBDataService;

    private Logger log = LoggerUtils.Logger(LogFileName.CabSwitchDataJob);

    /**
     * vlan长的 调用readline方法后，关闭inputStreamReader时会关闭inputStream,所以把处理vlan放在最后*
     */
    @Override
    public void execute() {
        String formatter="yyyy-MM-dd HH:mm:00";
        //十五分钟前的时间
        String beforeData=DateUtils.getMinutePlus(-15,formatter);
        //当前时间
        String programDate= DateUtils.dateTimeNow(formatter);

        Map<String,SwitchPortData> beforeSwitchPortDataMap=switchDBDataService.getBeforeMinuteData(beforeData);

        /**
         * 存储switch相关命令的结果
         */
        List<SwitchTotalData> switchTotalDataList=new ArrayList<>();
        /**
         * 存储Switch相关命令结果中接口流量数据
         */
        List<SwitchPortData> switchPortDataList=new ArrayList<>();
        /**
         * 存储Switch相关命令结果中接口状态数据
         */
        List<SwitchInterfaceStatus> switchInterfaceStatusList=new ArrayList<>();

        log.info("CabSwitchDataTask execute start");
        log.info("CabSwitchDataTask query switchList start");
        /**
         * 获取数据库中交换机集合
         */
        List<CabSwitch> cabSwitches=switchDBDataService.getSwitchList();
        /**
         * 获取数据字典中的交换机状态
         */
        Map<String,String> statusMap=switchDBDataService.getSysDictData();
        log.info("CabSwitchDataTask query switchList end size:"+cabSwitches.size());
        for (CabSwitch cabSwitch:cabSwitches){
            try {
                switch (cabSwitch.getBrand()) {
                    case "H3C":
                        executeH3C(cabSwitch, switchTotalDataList, switchPortDataList, switchInterfaceStatusList, statusMap, programDate, beforeSwitchPortDataMap);
                        break;
                    case "RJ":
                        executeRJ(cabSwitch, switchTotalDataList, switchPortDataList, switchInterfaceStatusList, statusMap, programDate, beforeSwitchPortDataMap);
                        break;
                    case "ZTE":
                        executeZTE(cabSwitch, switchTotalDataList, switchPortDataList, switchInterfaceStatusList, statusMap, programDate, beforeSwitchPortDataMap);
                        break;
                    case "DELL":
                        executeDELL(cabSwitch, switchTotalDataList, switchPortDataList, switchInterfaceStatusList, statusMap, programDate, beforeSwitchPortDataMap);
                        break;
                    case "HW":
                        executeHW(cabSwitch, switchTotalDataList, switchPortDataList, switchInterfaceStatusList, statusMap, programDate, beforeSwitchPortDataMap);
                        break;
                    case "EXTREME":
                        executeEXTREME(cabSwitch, switchTotalDataList, switchPortDataList, switchInterfaceStatusList, statusMap, programDate, beforeSwitchPortDataMap);
                        break;
                }
            }catch(Exception ex){
                log.error(cabSwitch.getAddress()+ex.getMessage());
            }
        }
        switchDBDataService.insertSwitchTotalList(switchTotalDataList);
        switchDBDataService.insertSwitchPortDataList(switchPortDataList,programDate);
        switchDBDataService.insertSwitchInterStatus(switchInterfaceStatusList);
        log.info("CabSwitchDataTask execute end");
    }

    /**
     * 处理H3C类型的交换机
     * @param cabSwitch
     */
    public void executeH3C(CabSwitch cabSwitch,List<SwitchTotalData> switchTotalDataList,List<SwitchPortData> switchPortDataList,List<SwitchInterfaceStatus> switchInterfaceStatusList,Map<String,String> statusMap,String programDate,Map<String,SwitchPortData> beforeSwitchPortDataMap){
        log.info("executeH3C login:"+cabSwitch.getAddress()+"start");
        TelnetUtils telnetUtils=new TelnetUtils(cabSwitch.getAddress(),port);
        telnetUtils.setUsernamePrompt("login:");
        telnetUtils.setLoginPrompt(null);
        String prompt=">";
        if(cabSwitch.getAddress().equals("10.163.166.51")){
            telnetUtils.login51(prompt);
        }else if(cabSwitch.getAddress().equals("10.163.166.61")){
            telnetUtils.login61(cabSwitch.getPassword(), prompt);
        }else {
            telnetUtils.login(cabSwitch.getUsername(), cabSwitch.getPassword(), prompt);
        }
        log.info("executeH3C login:"+cabSwitch.getAddress()+"end");
        log.info("executeH3C "+cabSwitch.getAddress()+"display page start");
        switchDataService_H3C.displayPage(telnetUtils,SwitchDataCommandUtils.H3C_DISABLE_COMMAND);
        log.info("executeH3C "+cabSwitch.getAddress()+"display page end");
        log.info("executeH3C "+cabSwitch.getAddress()+"version start");
        SwitchTotalData switchTotalData=switchDataService_H3C.getUpTime(telnetUtils,SwitchDataCommandUtils.H3C_VERSION_COMMAND);
        log.info("executeH3C "+cabSwitch.getAddress()+"version end");
        log.info("executeH3C "+cabSwitch.getAddress()+"alarm start");
        String alarm=switchDataService_H3C.getAlarm(telnetUtils,SwitchDataCommandUtils.H3C_ALARM_COMMAND);
        //如果设备不识别上述命令，需要重新发送新的命令
        if(alarm.contains("command found")){
            alarm=switchDataService_H3C.getAlarm(telnetUtils,SwitchDataCommandUtils.H3C_ALARM_COMMAND_2);
        }
        switchTotalData.setAlarm(alarm.replaceAll("\r",""));
        log.info("executeH3C "+cabSwitch.getAddress()+"alarm end");
        log.info("executeH3C "+cabSwitch.getAddress()+"interface start");
        String interfaceS=switchDataService_H3C.getInterface(telnetUtils,SwitchDataCommandUtils.H3C_INTERFACE_COMMAND);
        log.info("executeH3C "+cabSwitch.getAddress()+"interface status start");
        List<SwitchInterfaceStatus> switchInterfaceStatusS=switchDataService_H3C.explainInterfaceStatus(interfaceS,cabSwitch.getName(),statusMap);
        switchInterfaceStatusList.addAll(switchInterfaceStatusS);
        log.info("executeH3C "+cabSwitch.getAddress()+"interface status end");
        switchTotalData.setSwitchInterface(interfaceS.replaceAll("\r",""));
        log.info("executeH3C "+cabSwitch.getAddress()+"interface end");
        log.info("executeH3C "+cabSwitch.getAddress()+"interface detail  start");
        List<SwitchPortData> switchPortDataListS=switchDataService_H3C.getInterfaceDetails(telnetUtils,SwitchDataCommandUtils.H3C_INTER_DETAIL_COMMAND,programDate,cabSwitch,beforeSwitchPortDataMap);
        log.info("executeH3C "+cabSwitch.getAddress()+"interface detail  end");
        switchPortDataList.addAll(switchPortDataListS);
        log.info("executeH3C "+cabSwitch.getAddress()+"ipv4Route start");
        String ipv4Route=switchDataService_H3C.getIpv4Route(telnetUtils,SwitchDataCommandUtils.H3C_IPV4_ROUTE_COMMAND);
        if(ipv4Route.contains("Wrong parameter found")){
            ipv4Route=switchDataService_H3C.getIpv4Route(telnetUtils,SwitchDataCommandUtils.H3C_IPV4_ROUTE_COMMAND2);
        }
        switchTotalData.setIpv4Route(ipv4Route.replaceAll("\r",""));
        log.info("executeH3C "+cabSwitch.getAddress()+"ipv4Route end");
        log.info("executeH3C "+cabSwitch.getAddress()+"ipv6Route start");
        String ipv6Route=switchDataService_H3C.getIpv6Route(telnetUtils,SwitchDataCommandUtils.H3C_IPV6_ROUTE_COMMAND);
        if(ipv6Route.contains("Wrong parameter found")){
            ipv6Route=switchDataService_H3C.getIpv6Route(telnetUtils,SwitchDataCommandUtils.H3C_IPV6_ROUTE_COMMAND2);
        }
        switchTotalData.setIpv6Route(ipv6Route.replaceAll("\r",""));
        log.info("executeH3C "+cabSwitch.getAddress()+"ipv6Route end");
        log.info("executeH3C "+cabSwitch.getAddress()+"config start");
        String config=switchDataService_H3C.getConfiguration(telnetUtils,SwitchDataCommandUtils.H3C_CONFIG_COMMAND);
        switchTotalData.setConfig(config.replaceAll("\r",""));
        log.info("executeH3C "+cabSwitch.getAddress()+"config end");
        log.info("executeH3C "+cabSwitch.getAddress()+"vlan start");
        String vlan=switchDataService_H3C.getVlan(telnetUtils,SwitchDataCommandUtils.H3C_VLAN_COMMAND);
        switchTotalData.setVlan(vlan.replaceAll("\r","").replaceAll("\n\n","\n"));
        log.info("executeH3C "+cabSwitch.getAddress()+"vlan end");
        log.info("executeH3C "+cabSwitch.getAddress()+"exit start");
        switchDataService_H3C.exitEquipment(telnetUtils,SwitchDataCommandUtils.H3C_QUIT_COMMAND);
        telnetUtils.disconnect();
        log.info("executeH3C "+cabSwitch.getAddress()+"exit end");
        switchTotalData.setIp(cabSwitch.getAddress());
        switchTotalData.setSwitchName(cabSwitch.getName());
        switchTotalDataList.add(switchTotalData);
    }

    /**
     * 处理RJ类型的交换机
     * @param cabSwitch
     */
    public void executeRJ(CabSwitch cabSwitch,List<SwitchTotalData> switchTotalDataList,List<SwitchPortData> switchPortDataList,List<SwitchInterfaceStatus> switchInterfaceStatusList,Map<String,String> statusMap,String programDate,Map<String,SwitchPortData> beforeSwitchPortDataMap){
        log.info("executeRJ login:"+cabSwitch.getAddress()+"start");
        TelnetUtils telnetUtils=new TelnetUtils(cabSwitch.getAddress(),port);
        telnetUtils.setUsernamePrompt("Username:");
        telnetUtils.setLoginPrompt(null);
        telnetUtils.login(cabSwitch.getUsername(),cabSwitch.getPassword(),">");
        telnetUtils.setPrompt("Password:");
        telnetUtils.sendCommand("enable");
        telnetUtils.setPrompt("#");
        telnetUtils.sendCommand("admin");
        log.info("executeRJ login:"+cabSwitch.getAddress()+"end");
        log.info("executeRJ "+cabSwitch.getAddress()+"display page start");
        switchDataService_rj.displayPage(telnetUtils,SwitchDataCommandUtils.RJ_DISABLE_COMMAND);
        log.info("executeRJ "+cabSwitch.getAddress()+"display page end");
        log.info("executeRJ "+cabSwitch.getAddress()+"version start");
        SwitchTotalData switchTotalData=switchDataService_rj.getUpTime(telnetUtils,SwitchDataCommandUtils.RJ_VERSION_COMMAND);
        log.info("executeRJ "+cabSwitch.getAddress()+"version end");
        log.info("executeRJ "+cabSwitch.getAddress()+"alarm start");
        String alarm=switchDataService_rj.getAlarm(telnetUtils,SwitchDataCommandUtils.RJ_ALARM_COMMAND);
        switchTotalData.setAlarm(alarm.replaceAll("\r",""));
        log.info("executeRJ "+cabSwitch.getAddress()+"alarm end");
        log.info("executeRJ "+cabSwitch.getAddress()+"interface start");
        String interfaceS=switchDataService_rj.getInterface(telnetUtils,SwitchDataCommandUtils.RJ_INTERFACE_COMMAND);
        log.info("executeRJ "+cabSwitch.getAddress()+"interface status start");
        List<SwitchInterfaceStatus> switchInterfaceStatusS=switchDataService_rj.explainInterfaceStatus(interfaceS,cabSwitch.getName(),statusMap);
        switchInterfaceStatusList.addAll(switchInterfaceStatusS);
        log.info("executeRJ "+cabSwitch.getAddress()+"interface status end");
        switchTotalData.setSwitchInterface(interfaceS.replaceAll("\r",""));
        log.info("executeRJ "+cabSwitch.getAddress()+"interface end");
        log.info("executeRJ "+cabSwitch.getAddress()+"interface detail  start");
        List<SwitchPortData> switchPortDataListS=switchDataService_rj.getInterfaceDetails(telnetUtils,SwitchDataCommandUtils.RJ_INTER_DETAIL_COMMAND,programDate,cabSwitch,beforeSwitchPortDataMap);
        switchPortDataList.addAll(switchPortDataListS);
        log.info("executeRJ "+cabSwitch.getAddress()+"interface detail  end");
        log.info("executeRJ "+cabSwitch.getAddress()+"vlan start");
        String vlan=switchDataService_rj.getVlan(telnetUtils,SwitchDataCommandUtils.RJ_VLAN_COMMAND);
        switchTotalData.setVlan(vlan.replaceAll("\r","").replaceAll("\n\n","\n"));
        log.info("executeRJ "+cabSwitch.getAddress()+"vlan end");
        log.info("executeRJ "+cabSwitch.getAddress()+"ipv4Route start");
        String ipv4Route=switchDataService_rj.getIpv4Route(telnetUtils,SwitchDataCommandUtils.RJ_IPV4_ROUTE_COMMAND);
        switchTotalData.setIpv4Route(ipv4Route.replaceAll("\r",""));
        log.info("executeRJ "+cabSwitch.getAddress()+"ipv4Route end");
        log.info("executeRJ "+cabSwitch.getAddress()+"ipv6Route start");
        String ipv6Route=switchDataService_rj.getIpv6Route(telnetUtils,SwitchDataCommandUtils.RJ_IPV6_ROUTE_COMMAND);
        switchTotalData.setIpv6Route(ipv6Route.replaceAll("\r",""));
        log.info("executeRJ "+cabSwitch.getAddress()+"ipv6Route end");
        log.info("executeRJ "+cabSwitch.getAddress()+"config start");
        String config=switchDataService_rj.getConfiguration(telnetUtils,SwitchDataCommandUtils.RJ_CONFIG_COMMAND);
        switchTotalData.setConfig(config.replaceAll("\r",""));
        log.info("executeRJ "+cabSwitch.getAddress()+"config end");
        log.info("executeRJ "+cabSwitch.getAddress()+"exit start");
        switchDataService_rj.exitEquipment(telnetUtils,SwitchDataCommandUtils.RJ_QUIT_COMMAND);
        telnetUtils.disconnect();
        log.info("executeRJ "+cabSwitch.getAddress()+"exit end");
        switchTotalData.setIp(cabSwitch.getAddress());
        switchTotalData.setSwitchName(cabSwitch.getName());
        switchTotalDataList.add(switchTotalData);
    }

    public void executeZTE(CabSwitch cabSwitch,List<SwitchTotalData> switchTotalDataList,List<SwitchPortData> switchPortDataList,List<SwitchInterfaceStatus> switchInterfaceStatusList,Map<String,String> statusMap,String programDate,Map<String,SwitchPortData> beforeSwitchPortDataMap) {
        log.info("executeZTE login:"+cabSwitch.getAddress()+"start");
        TelnetUtils telnetUtils=new TelnetUtils(cabSwitch.getAddress(),port);
        telnetUtils.setUsernamePrompt("Username:");
        telnetUtils.setLoginPrompt(null);
        telnetUtils.login(cabSwitch.getUsername(),cabSwitch.getPassword(),"#");
        log.info("executeZTE login:"+cabSwitch.getAddress()+"end");
        log.info("executeZTE "+cabSwitch.getAddress()+"display page start");
        switchDataService_zte.displayPage(telnetUtils,SwitchDataCommandUtils.ZTE_DISABLE_COMMAND);
        log.info("executeZTE "+cabSwitch.getAddress()+"display page end");
        log.info("executeZTE "+cabSwitch.getAddress()+"version start");
        SwitchTotalData switchTotalData=switchDataService_zte.getUpTime(telnetUtils,SwitchDataCommandUtils.ZTE_VERSION_COMMAND);
        log.info("executeZTE "+cabSwitch.getAddress()+"version end");
        log.info("executeZTE "+cabSwitch.getAddress()+"alarm start");
        String alarm=switchDataService_zte.getAlarm(telnetUtils,SwitchDataCommandUtils.ZTE_ALARM_COMMAND);
        switchTotalData.setAlarm(alarm.replaceAll("\r",""));
        log.info("executeZTE "+cabSwitch.getAddress()+"alarm end");
        log.info("executeZTE "+cabSwitch.getAddress()+"interface start");
        String interfaceS=switchDataService_zte.getInterface(telnetUtils,SwitchDataCommandUtils.ZTE_INTERFACE_COMMAND);
        log.info("executeZTE "+cabSwitch.getAddress()+"interface status start");
        List<SwitchInterfaceStatus> switchInterfaceStatusS=switchDataService_zte.explainInterfaceStatus(interfaceS,cabSwitch.getName(),statusMap);
        switchInterfaceStatusList.addAll(switchInterfaceStatusS);
        log.info("executeZTE "+cabSwitch.getAddress()+"interface status end");
        switchTotalData.setSwitchInterface(interfaceS.replaceAll("\r",""));
        log.info("executeZTE "+cabSwitch.getAddress()+"interface end");
        log.info("executeZTE "+cabSwitch.getAddress()+"interface detail  start");
        List<SwitchPortData> switchPortDataListS=switchDataService_zte.getInterfaceDetails(telnetUtils,SwitchDataCommandUtils.ZTE_INTER_DETAIL_COMMAND,programDate,cabSwitch,beforeSwitchPortDataMap);
        switchPortDataList.addAll(switchPortDataListS);
        log.info("executeZTE "+cabSwitch.getAddress()+"interface detail  end");
        log.info("executeZTE "+cabSwitch.getAddress()+"ipv4Route start");
        String ipv4Route=switchDataService_zte.getIpv4Route(telnetUtils,SwitchDataCommandUtils.ZTE_IPV4_ROUTE_COMMAND);
        switchTotalData.setIpv4Route(ipv4Route.replaceAll("\r",""));
        log.info("executeZTE "+cabSwitch.getAddress()+"ipv4Route end");
        log.info("executeZTE "+cabSwitch.getAddress()+"ipv6Route start");
        String ipv6Route=switchDataService_zte.getIpv6Route(telnetUtils,SwitchDataCommandUtils.ZTE_IPV6_ROUTE_COMMAND);
        switchTotalData.setIpv6Route(ipv6Route.replaceAll("\r",""));
        log.info("executeZTE "+cabSwitch.getAddress()+"ipv6Route end");
        log.info("executeZTE "+cabSwitch.getAddress()+"config start");
        String config=switchDataService_zte.getConfiguration(telnetUtils,SwitchDataCommandUtils.ZTE_CONFIG_COMMAND);
        switchTotalData.setConfig(config.replaceAll("\r",""));
        log.info("executeZTE "+cabSwitch.getAddress()+"config end");
        log.info("executeZTE "+cabSwitch.getAddress()+"vlan start");
        String vlan=switchDataService_zte.getVlan(telnetUtils,SwitchDataCommandUtils.ZTE_VLAN_COMMAND);
        switchTotalData.setVlan(vlan.replaceAll("\r","").replaceAll("\n\n","\n"));
        log.info("executeZTE "+cabSwitch.getAddress()+"vlan end");
        log.info("executeZTE "+cabSwitch.getAddress()+"exit start");
        switchDataService_rj.exitEquipment(telnetUtils,SwitchDataCommandUtils.ZTE_QUIT_COMMAND);
        telnetUtils.disconnect();
        log.info("executeZTE "+cabSwitch.getAddress()+"exit end");
        switchTotalData.setIp(cabSwitch.getAddress());
        switchTotalData.setSwitchName(cabSwitch.getName());
        switchTotalDataList.add(switchTotalData);
    }

    public void executeDELL(CabSwitch cabSwitch,List<SwitchTotalData> switchTotalDataList,List<SwitchPortData> switchPortDataList,List<SwitchInterfaceStatus> switchInterfaceStatusList,Map<String,String> statusMap,String programDate,Map<String,SwitchPortData> beforeSwitchPortDataMap) {
        log.info("executeDELL login:"+cabSwitch.getAddress()+"start");
        TelnetUtils telnetUtils=new TelnetUtils(cabSwitch.getAddress(),port);
        telnetUtils.setUsernamePrompt("Login:");
        telnetUtils.setLoginPrompt(null);
        telnetUtils.login(cabSwitch.getUsername(),cabSwitch.getPassword(),"#");
        log.info("executeDELL login:"+cabSwitch.getAddress()+"end");
        log.info("executeDELL "+cabSwitch.getAddress()+"display page start");
        switchDataService_dell.displayPage(telnetUtils,SwitchDataCommandUtils.DELL_DISABLE_COMMAND);
        log.info("executeDELL "+cabSwitch.getAddress()+"display page end");
        log.info("executeDELL "+cabSwitch.getAddress()+"version start");
        SwitchTotalData switchTotalData=switchDataService_dell.getUpTime(telnetUtils,SwitchDataCommandUtils.DELL_VERSION_COMMAND);
        log.info("executeDELL "+cabSwitch.getAddress()+"version end");
        log.info("executeDELL "+cabSwitch.getAddress()+"alarm start");
        String alarm=switchDataService_dell.getAlarm(telnetUtils,SwitchDataCommandUtils.DELL_ALARM_COMMAND);
        switchTotalData.setAlarm(alarm.replaceAll("\r",""));
        log.info("executeDELL "+cabSwitch.getAddress()+"alarm end");
        log.info("executeDELL "+cabSwitch.getAddress()+"interface start");
        String interfaceS=switchDataService_dell.getInterface(telnetUtils,SwitchDataCommandUtils.DELL_INTERFACE_COMMAND);
        log.info("executeDELL "+cabSwitch.getAddress()+"interface status start");
        List<SwitchInterfaceStatus> switchInterfaceStatusS=switchDataService_dell.explainInterfaceStatus(interfaceS,cabSwitch.getName(),statusMap);
        switchInterfaceStatusList.addAll(switchInterfaceStatusS);
        log.info("executeDELL "+cabSwitch.getAddress()+"interface status end");
        switchTotalData.setSwitchInterface(interfaceS.replaceAll("\r",""));
        log.info("executeDELL "+cabSwitch.getAddress()+"interface end");
        log.info("executeDELL "+cabSwitch.getAddress()+"interface detail  start");
        List<SwitchPortData> switchPortDataListS=switchDataService_dell.getInterfaceDetails(telnetUtils,SwitchDataCommandUtils.DELL_INTER_DETAIL_COMMAND,programDate,cabSwitch,beforeSwitchPortDataMap);
        switchPortDataList.addAll(switchPortDataListS);
        log.info("executeDELL "+cabSwitch.getAddress()+"interface detail  end");
        log.info("executeDELL "+cabSwitch.getAddress()+"ipv4Route start");
        String ipv4Route=switchDataService_dell.getIpv4Route(telnetUtils,SwitchDataCommandUtils.DELL_IPV4_ROUTE_COMMAND);
        switchTotalData.setIpv4Route(ipv4Route.replaceAll("\r",""));
        log.info("executeDELL "+cabSwitch.getAddress()+"ipv4Route end");
        log.info("executeDELL "+cabSwitch.getAddress()+"ipv6Route start");
        String ipv6Route=switchDataService_dell.getIpv6Route(telnetUtils,SwitchDataCommandUtils.DELL_IPV6_ROUTE_COMMAND);
        switchTotalData.setIpv6Route(ipv6Route.replaceAll("\r",""));
        log.info("executeDELL "+cabSwitch.getAddress()+"ipv6Route end");
        log.info("executeDELL "+cabSwitch.getAddress()+"config start");
        String config=switchDataService_dell.getConfiguration(telnetUtils,SwitchDataCommandUtils.DELL_CONFIG_COMMAND);
        switchTotalData.setConfig(config.replaceAll("\r",""));
        log.info("executeDELL "+cabSwitch.getAddress()+"config end");
        log.info("executeDELL "+cabSwitch.getAddress()+"vlan start");
        String vlan=switchDataService_dell.getVlan(telnetUtils,SwitchDataCommandUtils.DELL_VLAN_COMMAND);
        switchTotalData.setVlan(vlan.replaceAll("\r","").replaceAll("\n\n","\n"));
        log.info("executeDELL "+cabSwitch.getAddress()+"vlan end");
        log.info("executeDELL "+cabSwitch.getAddress()+"exit start");
        switchDataService_dell.exitEquipment(telnetUtils,SwitchDataCommandUtils.DELL_QUIT_COMMAND);
        telnetUtils.disconnect();
        log.info("executeDELL "+cabSwitch.getAddress()+"exit end");
        switchTotalData.setIp(cabSwitch.getAddress());
        switchTotalData.setSwitchName(cabSwitch.getName());
        switchTotalDataList.add(switchTotalData);
    }

    public void executeHW(CabSwitch cabSwitch,List<SwitchTotalData> switchTotalDataList,List<SwitchPortData> switchPortDataList,List<SwitchInterfaceStatus> switchInterfaceStatusList,Map<String,String> statusMap,String programDate,Map<String,SwitchPortData> beforeSwitchPortDataMap) {
        log.info("executeHW login:"+cabSwitch.getAddress()+"start");
        TelnetUtils telnetUtils=new TelnetUtils(cabSwitch.getAddress(),port);
        telnetUtils.setLoginPrompt(null);
        telnetUtils.login(cabSwitch.getUsername(),cabSwitch.getPassword(),">");
        log.info("executeHW login:"+cabSwitch.getAddress()+"end");
        log.info("executeHW "+cabSwitch.getAddress()+"display page start");
        switchDataService_hw.displayPage(telnetUtils,SwitchDataCommandUtils.HW_DISABLE_COMMAND);
        log.info("executeHW "+cabSwitch.getAddress()+"display page end");
        log.info("executeHW "+cabSwitch.getAddress()+"version start");
        SwitchTotalData switchTotalData=switchDataService_hw.getUpTime(telnetUtils,SwitchDataCommandUtils.HW_VERSION_COMMAND);
        log.info("executeHW "+cabSwitch.getAddress()+"version end");
        log.info("executeHW "+cabSwitch.getAddress()+"alarm start");
        String alarm=switchDataService_hw.getAlarm(telnetUtils,SwitchDataCommandUtils.HW_ALARM_COMMAND);
        switchTotalData.setAlarm(alarm.replaceAll("\r",""));
        log.info("executeHW "+cabSwitch.getAddress()+"alarm end");
        log.info("executeHW "+cabSwitch.getAddress()+"interface start");
        String interfaceS=switchDataService_hw.getInterface(telnetUtils,SwitchDataCommandUtils.HW_INTERFACE_COMMAND);
        log.info("executeHW "+cabSwitch.getAddress()+"interface status start");
        List<SwitchInterfaceStatus> switchInterfaceStatusS=switchDataService_hw.explainInterfaceStatus(interfaceS,cabSwitch.getName(),statusMap);
        switchInterfaceStatusList.addAll(switchInterfaceStatusS);
        log.info("executeHW "+cabSwitch.getAddress()+"interface status end");
        switchTotalData.setSwitchInterface(interfaceS.replaceAll("\r",""));
        log.info("executeHW "+cabSwitch.getAddress()+"interface end");
        log.info("executeHW "+cabSwitch.getAddress()+"interface detail  start");
        List<SwitchPortData> switchPortDataListS=switchDataService_hw.getInterfaceDetails(telnetUtils,SwitchDataCommandUtils.HW_INTER_DETAIL_COMMAND,programDate,cabSwitch,beforeSwitchPortDataMap);
        switchPortDataList.addAll(switchPortDataListS);
        log.info("executeHW "+cabSwitch.getAddress()+"interface detail  end");
        log.info("executeHW "+cabSwitch.getAddress()+"ipv4Route start");
        String ipv4Route=switchDataService_hw.getIpv4Route(telnetUtils,SwitchDataCommandUtils.HW_IPV4_ROUTE_COMMAND);
        switchTotalData.setIpv4Route(ipv4Route.replaceAll("\r",""));
        log.info("executeHW "+cabSwitch.getAddress()+"ipv4Route end");
        log.info("executeHW "+cabSwitch.getAddress()+"ipv6Route start");
        String ipv6Route=switchDataService_hw.getIpv6Route(telnetUtils,SwitchDataCommandUtils.HW_IPV6_ROUTE_COMMAND);
        switchTotalData.setIpv6Route(ipv6Route.replaceAll("\r",""));
        log.info("executeHW "+cabSwitch.getAddress()+"ipv6Route end");
        log.info("executeHW "+cabSwitch.getAddress()+"config start");
        String config=switchDataService_hw.getConfiguration(telnetUtils,SwitchDataCommandUtils.HW_CONFIG_COMMAND);
        switchTotalData.setConfig(config.replaceAll("\r",""));
        log.info("executeHW "+cabSwitch.getAddress()+"config end");
        log.info("executeHW "+cabSwitch.getAddress()+"vlan start");
        String vlan=switchDataService_hw.getVlan(telnetUtils,SwitchDataCommandUtils.HW_VLAN_COMMAND);
        switchTotalData.setVlan(vlan.replaceAll("\r","").replaceAll("\n\n","\n"));
        log.info("executeHW "+cabSwitch.getAddress()+"vlan end");
        log.info("executeHW "+cabSwitch.getAddress()+"exit start");
        switchDataService_hw.exitEquipment(telnetUtils,SwitchDataCommandUtils.HW_QUIT_COMMAND);
        telnetUtils.disconnect();
        log.info("executeHW "+cabSwitch.getAddress()+"exit end");
        switchTotalData.setIp(cabSwitch.getAddress());
        switchTotalData.setSwitchName(cabSwitch.getName());
        switchTotalDataList.add(switchTotalData);
    }

    public void executeEXTREME(CabSwitch cabSwitch,List<SwitchTotalData> switchTotalDataList,List<SwitchPortData> switchPortDataList,List<SwitchInterfaceStatus> switchInterfaceStatusList,Map<String,String> statusMap,String programDate,Map<String,SwitchPortData> beforeSwitchPortDataMap) {
        log.info("executeEXTREME login:"+cabSwitch.getAddress()+"start");
        TelnetUtils telnetUtils=new TelnetUtils(cabSwitch.getAddress(),port);
        telnetUtils.setUsernamePrompt("login:");
        telnetUtils.setPasswordPrompt("password:");
        telnetUtils.setLoginPrompt(null);
        telnetUtils.login(cabSwitch.getUsername(),cabSwitch.getPassword(),"#");
        log.info("executeEXTREME login:"+cabSwitch.getAddress()+"end");
        log.info("executeEXTREME "+cabSwitch.getAddress()+"display page start");
        switchDataService_extreme.displayPage(telnetUtils,SwitchDataCommandUtils.EXTREME_DISABLE_COMMAND);
        log.info("executeEXTREME "+cabSwitch.getAddress()+"display page end");
        log.info("executeEXTREME "+cabSwitch.getAddress()+"version start");
        SwitchTotalData switchTotalData=switchDataService_extreme.getUpTime(telnetUtils,SwitchDataCommandUtils.EXTREME_VERSION_COMMAND);
        log.info("executeEXTREME "+cabSwitch.getAddress()+"version end");
        log.info("executeEXTREME "+cabSwitch.getAddress()+"alarm start");
        String alarm=switchDataService_extreme.getAlarm(telnetUtils,SwitchDataCommandUtils.EXTREME_ALARM_COMMAND);
        switchTotalData.setAlarm(alarm.replaceAll("\r",""));
        log.info("executeEXTREME "+cabSwitch.getAddress()+"alarm end");
        log.info("executeEXTREME "+cabSwitch.getAddress()+"interface start");
        String interfaceS=switchDataService_extreme.getInterface(telnetUtils,SwitchDataCommandUtils.EXTREME_INTERFACE_COMMAND);
        log.info("executeEXTREME "+cabSwitch.getAddress()+"interface status start");
        List<SwitchInterfaceStatus> switchInterfaceStatusS=switchDataService_extreme.explainInterfaceStatus(interfaceS,cabSwitch.getName(),statusMap);
        switchInterfaceStatusList.addAll(switchInterfaceStatusS);
        log.info("executeEXTREME "+cabSwitch.getAddress()+"interface status end");
        switchTotalData.setSwitchInterface(interfaceS.replaceAll("\r",""));
        log.info("executeEXTREME "+cabSwitch.getAddress()+"interface end");
        log.info("executeEXTREME "+cabSwitch.getAddress()+"interface detail  start");
        List<SwitchPortData> switchPortDataListS=switchDataService_extreme.getInterfaceDetails(telnetUtils,SwitchDataCommandUtils.EXTREME_INTER_DETAIL_COMMAND,programDate,cabSwitch,beforeSwitchPortDataMap);
        switchPortDataList.addAll(switchPortDataListS);
        log.info("executeEXTREME "+cabSwitch.getAddress()+"interface detail  end");
        log.info("executeEXTREME "+cabSwitch.getAddress()+"ipv4Route start");
        String ipv4Route=switchDataService_extreme.getIpv4Route(telnetUtils,SwitchDataCommandUtils.EXTREME_IPV4_ROUTE_COMMAND);
        switchTotalData.setIpv4Route(ipv4Route.replaceAll("\r",""));
        log.info("executeEXTREME "+cabSwitch.getAddress()+"ipv4Route end");
        log.info("executeEXTREME "+cabSwitch.getAddress()+"ipv6Route start");
        String ipv6Route=switchDataService_extreme.getIpv6Route(telnetUtils,SwitchDataCommandUtils.EXTREME_IPV6_ROUTE_COMMAND);
        switchTotalData.setIpv6Route(ipv6Route.replaceAll("\r",""));
        log.info("executeEXTREME "+cabSwitch.getAddress()+"ipv6Route end");
        log.info("executeEXTREME "+cabSwitch.getAddress()+"config start");
        String config=switchDataService_extreme.getConfiguration(telnetUtils,SwitchDataCommandUtils.EXTREME_CONFIG_COMMAND);
        switchTotalData.setConfig(config.replaceAll("\r",""));
        log.info("executeEXTREME "+cabSwitch.getAddress()+"config end");
        log.info("executeEXTREME "+cabSwitch.getAddress()+"vlan start");
        String vlan=switchDataService_extreme.getVlan(telnetUtils,SwitchDataCommandUtils.EXTREME_VLAN_COMMAND);
        switchTotalData.setVlan(vlan.replaceAll("\r","").replaceAll("\n\n","\n"));
        log.info("executeEXTREME "+cabSwitch.getAddress()+"vlan end");
        log.info("executeEXTREME "+cabSwitch.getAddress()+"exit start");
        switchDataService_extreme.exitEquipment(telnetUtils,SwitchDataCommandUtils.EXTREME_QUIT_COMMAND);
        telnetUtils.disconnect();
        log.info("executeEXTREME "+cabSwitch.getAddress()+"exit end");
        switchTotalData.setIp(cabSwitch.getAddress());
        switchTotalData.setSwitchName(cabSwitch.getName());
        switchTotalDataList.add(switchTotalData);
    }
}
